package com.mlink.ai.chat.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.mlink.ai.chat.assistant.robot.R
import com.mlink.ai.chat.assistant.robot.databinding.ItemFeedbackQuestionCategoryBinding

class FeedbackCategoryRecyclerAdapter :
    RecyclerView.Adapter<FeedbackCategoryRecyclerAdapter.CategoryViewHolder>() {

    var data = mutableListOf<String>()
    var selectedData = mutableListOf<String>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder {
        return CategoryViewHolder(
            ItemFeedbackQuestionCategoryBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: CategoryViewHolder, position: Int) {
        holder.binding.run {
            val item = data[position]
            tvCategory.text = item
            root.setOnClickListener {
                if (selectedData.contains(item)) {
                    tvCategory
                        .setTextColor(root.context.resources.getColor(R.color.white))
                    tvCategory.setBackgroundResource(R.drawable.shape_bg_feedback_question_category_unselect)
                    selectedData.remove(item)
                    return@setOnClickListener
                }
                tvCategory.setTextColor(root.context.resources.getColor(R.color.feedback_category_select))
                tvCategory.setBackgroundResource(R.drawable.shape_bg_feedback_question_category_select)
                selectedData.add(item)
            }
        }
    }

    inner class CategoryViewHolder(val binding: ItemFeedbackQuestionCategoryBinding) :
        RecyclerView.ViewHolder(binding.root)


}